package com.itheima.d1_Collection_Api;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.function.Consumer;

/**
 * 集合的遍历：1.iterator
 *           2.for(推荐)---->集合、数组、对象都可以用
 *           3/Lambda
 * 遍历时无法修改，不会影响数组/集合的元素值
 */
public class demo2 {
    public static void main(String[] args) {
        Collection<String> list = new ArrayList();
        list.add("赵");
        list.add("钱");
        list.add("孙");
        list.add("李");
        System.out.println(list);

        //1.得到当前集合迭代器
        Iterator<String> iterator = list.iterator();
//        String ele = iterator.next();
//        System.out.println(ele);
//        System.out.println(iterator.next());
//        System.out.println(iterator.next());
//        System.out.println(iterator.next());
        //2
        while (iterator.hasNext()){
            String ele = iterator.next();
            System.out.println(ele);
        }
        System.out.println("====================================");
        //3
        for (String s : list) {
            System.out.println(s);
        }
        System.out.println("====================================");
        //4
//        list.forEach(new Consumer<String>() {
//            @Override
//            public void accept(String s) {
//                System.out.println(s);
//            }
//        });

        list.forEach(s -> {
            System.out.println(s);
        });
    }
}
